const mongoose = require("mongoose");
const ObjectId = mongoose.Schema.Types.ObjectId;
const OrderSchema = new mongoose.Schema({
    // 商品数据模型
    name: String,    //订单名
    price: String,    //订单价格
    time: Date,    //时间
    state: String,  //订单的状态
    Petowners: {//关联的对象
        type: ObjectId,
        ref: "Petowners"//宠物主订单
    }
}, {
        versionKey: false,
        timestamps: {
            createdAt: 'createTime',
            updatedAt: 'updateTime'
        } //自动管理修改时间
    })
const order = mongoose.model("order", OrderSchema);

async function add() {
    const count = await order.countDocuments();
    if (count === 0) {
        order.create({
            name: "粉色小猫咪",
            price: "2000",
            time: ""
        })
    }
}
add();
module.exports = order;